package com.ld.admin.util.daliySentence.impl;

import com.alibaba.fastjson.JSONObject;
import com.ld.admin.util.daliySentence.DaliySentence;
import com.ld.admin.util.daliySentence.DaliySentenceUtil;
import com.ld.admin.util.daliySentence.model.DaliySentenceModel;
import com.ld.shieldsb.common.core.util.JsoupUtil;

/**
 * 
 * 木芽一言
 * 
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2020年1月8日 上午11:00:38
 *
 */
public class DaliySentenceDailywd implements DaliySentence {
    public static final String KEY = "muyayiye";
    public static final String NAME = "木芽一言"; // 木芽一言
    public static final String URL = "https://api.xygeng.cn/one"; // 木芽一言
    public static final String LINK_URL = "http://api.xygeng.cn"; // 木芽一言
    public static final String DESCRIPTION = "开源api系统，将会汇集搜集开源的所有api接口，个人开发简版操作。提供ONE一句，必应每日一图，新闻接口，宝塔接口，小说接口，微信接口，球赛接口，邮件接口"; // 描述

    @Override
    public DaliySentenceModel getSentence() {
        String htmlContent = null;
        DaliySentenceModel model = null;
        JSONObject jsonObj = JsoupUtil.getRemoteURLJson(getURL());
        /*{
            "code": 200,
            "data": {
                "id": "807",
                "tag": "漫画",//主题
                "origin": "《萤火之森》",//来自
                "content": "其实美丽的故事都是没有结局的，只因为它没有结局所以才会美丽。",//内容
                "datetime": "1548230343"
            }
        }*/
        if (jsonObj != null) {
            model = new DaliySentenceModel();
            JSONObject dataResult = jsonObj.getJSONObject("data");
            String origin = dataResult.getString("origin");
            htmlContent = dataResult.getString("content") + "——" + origin + DaliySentenceUtil.getLinkedStr(getLinkURL(), getName());

            model.setHtmlContent(htmlContent);
            model.setContent(dataResult.getString("content"));
            model.setOrigin(origin);
            model.setBaseInfo(getBaseInfo());
        }
        return model;
    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getURL() {
        return URL;
    }

    @Override
    public String getLinkURL() {
        return LINK_URL;
    }

    @Override
    public String getDescription() {
        return DESCRIPTION;
    }

}
